package com.kinyx.framework.tree;

import java.util.List;

import javax.util.XArrayList;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.Configs;
import com.kinyx.framework.utils.KArrayUtils;

public class KCodeUtils_Tester_ {

	final String codeA0000001 = "A0000001B0000000C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000001_real = "A0000001";
	final String codeA0000001B0000001 = "A0000001B0000001C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000001B0000001_real = "A0000001B0000001";
	final String codeA0000001B0000002 = "A0000001B0000002C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000002 = "A0000002B0000000C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000002B0000001 = "A0000002B0000001C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000009 = "A0000009B0000000C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000010 = "A0000010B0000000C0000000D0000000E0000000F0000000G0000000H0000000";
	final String codeA0000010_real = "A0000010";

	@Test
	public void test11() {
		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(null));
		Assert.assertEquals(this.codeA0000001, KCodeUtils.create("null"));

		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(""));
		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(" "));

		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(Configs.ROOT));
	}

	@Test
	public void test12() {
		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(null, 0));
		Assert.assertEquals(this.codeA0000001, KCodeUtils.create("null", 0));

		Assert.assertEquals(this.codeA0000001, KCodeUtils.create("", 0));
		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(" ", 0));

		Assert.assertEquals(this.codeA0000001, KCodeUtils.create(Configs.ROOT, 0));
	}

	@Test
	public void test13() {
		Assert.assertEquals(this.codeA0000010, KCodeUtils.create(null, 9));
		Assert.assertEquals(this.codeA0000010, KCodeUtils.create("null", 9));

		Assert.assertEquals(this.codeA0000010, KCodeUtils.create("", 9));
		Assert.assertEquals(this.codeA0000010, KCodeUtils.create(" ", 9));

		Assert.assertEquals(this.codeA0000010, KCodeUtils.create(Configs.ROOT, 9));
	}

	@Test
	public void test14() {
		Assert.assertEquals(this.codeA0000001B0000001, KCodeUtils.create(this.codeA0000001));
		Assert.assertEquals(this.codeA0000001B0000001, KCodeUtils.create(this.codeA0000001, 0));
		Assert.assertEquals(this.codeA0000001B0000002, KCodeUtils.create(this.codeA0000001, 1));
	}

	@Test
	public void test2() {
		Assert.assertEquals(0, KCodeUtils.level(null));
		Assert.assertEquals(0, KCodeUtils.level("null"));

		Assert.assertEquals(0, KCodeUtils.level(""));
		Assert.assertEquals(0, KCodeUtils.level(" "));

		Assert.assertEquals(0, KCodeUtils.level(Configs.ROOT));

		Assert.assertEquals(1, KCodeUtils.level(this.codeA0000001));
		Assert.assertEquals(2, KCodeUtils.level(this.codeA0000001B0000001));
	}

	@Test
	public void test3() {
		Assert.assertEquals("", KCodeUtils.real(null));
		Assert.assertEquals("", KCodeUtils.real("null"));

		Assert.assertEquals("", KCodeUtils.real(""));
		Assert.assertEquals("", KCodeUtils.real(" "));

		Assert.assertEquals("", KCodeUtils.real(Configs.ROOT));

		Assert.assertEquals(this.codeA0000001_real, KCodeUtils.real(this.codeA0000001));
		Assert.assertEquals(this.codeA0000010_real, KCodeUtils.real(this.codeA0000010));
		Assert.assertEquals(this.codeA0000001B0000001_real, KCodeUtils.real(this.codeA0000001B0000001));
	}

	@Test
	public void test4() {
		Assert.assertEquals(Configs.ROOT, KCodeUtils.fill(null));
		Assert.assertEquals(Configs.ROOT, KCodeUtils.fill("null"));

		Assert.assertEquals(Configs.ROOT, KCodeUtils.fill(""));
		Assert.assertEquals(Configs.ROOT, KCodeUtils.fill(" "));

		Assert.assertEquals(Configs.ROOT, KCodeUtils.fill(Configs.ROOT));

		Assert.assertEquals(this.codeA0000001, KCodeUtils.fill(this.codeA0000001_real));
		Assert.assertEquals(this.codeA0000010, KCodeUtils.fill(this.codeA0000010_real));
		Assert.assertEquals(this.codeA0000001B0000001, KCodeUtils.fill(this.codeA0000001B0000001_real));
	}

	@Test
	public void test5() {
		Assert.assertEquals(this.codeA0000002, KCodeUtils.next(this.codeA0000001));
		Assert.assertEquals(this.codeA0000001, KCodeUtils.prev(this.codeA0000002));

		Assert.assertEquals(this.codeA0000010, KCodeUtils.next(this.codeA0000009));
		Assert.assertEquals(this.codeA0000009, KCodeUtils.prev(this.codeA0000010));

		Assert.assertEquals(this.codeA0000001B0000002, KCodeUtils.next(this.codeA0000001B0000001));
		Assert.assertEquals(this.codeA0000001B0000001, KCodeUtils.prev(this.codeA0000001B0000002));
	}

	private void test(final List<String> list1, final List<String> list2) {
		Assert.assertArrayEquals(KArrayUtils.toArray(list1), KArrayUtils.toArray(list2));
	}

	@Test
	public void test6() {
		this.test(new XArrayList<String>(), KCodeUtils.parentsCodes(this.codeA0000001, false));
		this.test(new XArrayList<String>().xAdd(Configs.ROOT), KCodeUtils.parentsCodes(this.codeA0000001, true));

		this.test(new XArrayList<String>().xAdd(this.codeA0000001), KCodeUtils.parentsCodes(this.codeA0000001B0000001, false));
		this.test(new XArrayList<String>().xAdd(this.codeA0000001).xAdd(Configs.ROOT), KCodeUtils.parentsCodes(this.codeA0000001B0000001, true));

		this.test(new XArrayList<String>().xAdd(this.codeA0000001), KCodeUtils.parentsCodes(this.codeA0000001B0000002, false));
		this.test(new XArrayList<String>().xAdd(this.codeA0000001).xAdd(Configs.ROOT), KCodeUtils.parentsCodes(this.codeA0000001B0000002, true));

		this.test(new XArrayList<String>().xAdd(this.codeA0000002), KCodeUtils.parentsCodes(this.codeA0000002B0000001, false));
		this.test(new XArrayList<String>().xAdd(this.codeA0000002).xAdd(Configs.ROOT), KCodeUtils.parentsCodes(this.codeA0000002B0000001, true));

		this.test(new XArrayList<String>()//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000000D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000000C0000000D0000000E0000000F0000000G0000000H0000000")//
				, KCodeUtils.parentsCodes("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000001", false));

		this.test(new XArrayList<String>()//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000000D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000000C0000000D0000000E0000000F0000000G0000000H0000000")//
				.xAdd(Configs.ROOT)//
				, KCodeUtils.parentsCodes("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000001", true));

		this.test(new XArrayList<String>()//
				.xAdd(this.codeA0000002)//
				.xAdd(this.codeA0000001)//
				, KCodeUtils.parentsCodes(new XArrayList<String>()//
						.xAdd(this.codeA0000001B0000001)//
						.xAdd(this.codeA0000002B0000001)//
						, false));

		this.test(new XArrayList<String>()//
				.xAdd(this.codeA0000002)//
				.xAdd(this.codeA0000001)//
				.xAdd(Configs.ROOT)//
				, KCodeUtils.parentsCodes(new XArrayList<String>()//
						.xAdd(this.codeA0000001B0000001)//
						.xAdd(this.codeA0000002B0000001)//
						, true));

		this.test(new XArrayList<String>()//
				.xAdd(this.codeA0000002)//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000000D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000000C0000000D0000000E0000000F0000000G0000000H0000000")//
				, KCodeUtils.parentsCodes(new XArrayList<String>()//
						.xAdd(this.codeA0000001B0000001)//
						.xAdd(this.codeA0000002B0000001)//
						.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000001")//
						, false));

		this.test(new XArrayList<String>()//
				.xAdd(this.codeA0000002)//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000001F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000001E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000001D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000001C0000000D0000000E0000000F0000000G0000000H0000000")//
				.xAdd("A0000001B0000000C0000000D0000000E0000000F0000000G0000000H0000000")//
				.xAdd(Configs.ROOT)//
				, KCodeUtils.parentsCodes(new XArrayList<String>()//
						.xAdd(this.codeA0000001B0000001)//
						.xAdd(this.codeA0000002B0000001)//
						.xAdd("A0000001B0000001C0000001D0000001E0000001F0000001G0000001H0000001")//
						, true));
	}

}
